﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;

namespace ZK.MyControl
{
  public  class SetWindowRegion
    {

        /// <summary>
        /// 绘制圆角窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="p_1"></param>
        /// <param name="p_2"></param>
        private static GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
        {

            int diameter = radius;

            Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));

            GraphicsPath path = new GraphicsPath();

            //   左上角   

            path.AddArc(arcRect, 180, 90);

            //   右上角   

            arcRect.X = rect.Right - diameter;

            path.AddArc(arcRect, 270, 90);

            //   右下角   

            arcRect.Y = rect.Bottom - diameter;

            path.AddArc(arcRect, 0, 90);

            //   左下角   

            arcRect.X = rect.Left;

            path.AddArc(arcRect, 90, 90);

            path.CloseFigure();

            return path;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="radius"></param>
        /// <param name="form"></param>
        public static void SetWindowSadius(int radius, System.Windows.Forms.Form form)
        {
            System.Drawing.Drawing2D.GraphicsPath FormPath;

            FormPath = new System.Drawing.Drawing2D.GraphicsPath();

            //Rectangle rect1 = new Rectangle(0, 22, form.Width, form.Height - 22);//this.Left-10,this.Top-10,this.Width-10,this.Height-10);  

            Rectangle rect = new Rectangle(0, 0, form.Width , form.Height);//; 
            FormPath = GetRoundedRectPath(rect, radius);
            form.Region = new Region(FormPath);
             
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="radius"></param>
        /// <param name="form"></param>
        public static void SetWindowSadius(int radius, System.Windows.Forms.Control control)
        {
            System.Drawing.Drawing2D.GraphicsPath controlPath;

            controlPath = new System.Drawing.Drawing2D.GraphicsPath();

            //Rectangle rect1 = new Rectangle(0, 22, form.Width, form.Height - 22);//this.Left-10,this.Top-10,this.Width-10,this.Height-10);  

            Rectangle rect = new Rectangle(0, 0, control.Width, control.Height);//; 
            controlPath = GetRoundedRectPath(rect, radius);
            control.Region = new Region(controlPath);

        }



    }
}
